//
//  FirstTableViewCell.m
//  iNews
//
//  Created by lanou3g on 14-12-8.
//  Copyright (c) 2014年 张在青. All rights reserved.
//

#import "FirstTableViewCell.h"
#import "HomeModel.h"
#import "UIImage+ImageDown.h"

#import "ShareDataHandle.h"

#import "UIImageView+WebCache.h"

@implementation FirstTableViewCell 

- (void)dealloc
{
    [_scroll release];
    [_imV release];
    [_page release];
    
    [super dealloc];
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        
        [self addAllViews];
        
    }
    return self;
}


- (void)addAllViews
{
  //  UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self.delegate action:@selector(doSomeWhilePan:)];
    
    //设置scrollView的内容
    self.scroll = [[[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 180)] autorelease];
    
    self.scroll.contentSize = CGSizeMake(self.scroll.frame.size.width * 5, 180);
    self.scroll.pagingEnabled = YES;
    self.scroll.showsHorizontalScrollIndicator = NO;
    self.scroll.showsVerticalScrollIndicator = NO;
    
//    UIImageView *imv = [[[UIImageView alloc] initWithFrame:CGRectMake(0 + [UIScreen mainScreen].bounds.size.width * 4, 0, [UIScreen mainScreen].bounds.size.width, self.scroll.frame.size.height * 0.9)] autorelease];
//   // imv.backgroundColor = [UIColor redColor];
//    [self.scroll addSubview:imv];
    
    
    //添加四张图片,四个lable,四个小图标(tag:101--112)
    for (int i = 0; i < 4; i ++) {
        UIImageView *imV = [[[UIImageView alloc] initWithFrame:CGRectMake(0 + [UIScreen mainScreen].bounds.size.width * i, 0, [UIScreen mainScreen].bounds.size.width, self.scroll.frame.size.height * 0.9)] autorelease];
        imV.tag = 101+i;
        imV.backgroundColor = [UIColor colorWithRed:0.5 green:0.5 blue:0.5 alpha:1];
        [self.scroll addSubview:imV];
        
        UIButton *button = [[[UIButton alloc] initWithFrame:CGRectMake(0 + [UIScreen mainScreen].bounds.size.width * i, 0, [UIScreen mainScreen].bounds.size.width, self.scroll.frame.size.height * 0.9)] autorelease];
        button.tag = 114+i;
     //   [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
        [self.scroll addSubview:button];
        
        
        UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(self.scroll.frame.size.width * 0.05 + [UIScreen mainScreen].bounds.size.width * i, self.scroll.frame.size.height * 0.9, self.scroll.frame.size.width * 0.7, self.scroll.frame.size.height * 0.1)] autorelease];
        label.font = [UIFont systemFontOfSize:12];
        label.tag = 105+i;
     //   label.backgroundColor = [UIColor orangeColor];
        [self.scroll addSubview:label];
        
        UIImageView *litterImV = [[[UIImageView alloc] initWithFrame:CGRectMake(self.scroll.frame.size.width * i, self.scroll.frame.size.height * 0.9, self.scroll.frame.size.width * 0.05, self.scroll.frame.size.height * 0.2)] autorelease];
        litterImV.tag = 109+i;
     //   litterImV.backgroundColor = [UIColor grayColor];
        [self.scroll addSubview:litterImV];
    }
    
    //设置page
    self.page = [[[UIPageControl alloc] initWithFrame:CGRectMake(self.scroll.frame.size.width * 0.8, self.scroll.frame.size.height * 0.9, self.scroll.frame.size.width * 0.2, self.scroll.frame.size.height * 0.1)] autorelease];
    self.page.tag = 113;
    self.page.pageIndicatorTintColor = [UIColor grayColor];
    self.page.currentPageIndicatorTintColor = [UIColor blackColor];
   // self.page.backgroundColor = [UIColor blackColor];

    
    [self.contentView addSubview:self.scroll];
    [self.contentView addSubview:self.page];
    
    
}

- (void)writeMessageWithHomeModel:(HomeModel *)home
{
    //第一张图片及 title
        UIImageView *imV = (UIImageView *)[self.scroll viewWithTag:101];
       
    [imV sd_setImageWithURL:[NSURL URLWithString:home.imgsrc] placeholderImage:[UIImage imageNamed:@"placehodel.png"]];
    
   // [imV addGestureRecognizer:pan];
    
        UILabel *label = (UILabel *)[self.scroll viewWithTag:105];
        label.text = home.title;
        
}

- (void)writeThreeMessage
{
    for (int i = 0; i < 3; i++) {
        
        HomeModel *model = [ShareDataHandle shareDataHandle].threeArray[i];
        
        UIImageView *imV2 = (UIImageView *)[self.scroll viewWithTag:102 + i];
        [imV2 sd_setImageWithURL:[NSURL URLWithString:model.imgsrc] placeholderImage:[UIImage imageNamed:@"placehodel.png"]];
//        UIImage *image1 = [UIImage imageWithUrlString:model.imgsrc myBlock:^(UIImage *image) {
//            //
//                    image1 = image;
//        }];
//        
//        UIButton *button = (UIButton *)[self.scroll viewWithTag:102 + i];
//       
//        [button setBackgroundImage:image1 forState:UIControlEventTouchUpInside];
        
        UILabel *label = (UILabel *)[self.scroll viewWithTag:106 + i];
        label.text = model.title;
    }
    
}

- (void)awakeFromNib
{
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}













@end
